(()=>{"use strict";const e="product_added_to_cart";function t(){return window}let n="OFF";function o(e,n,o){const{jQuery:r}=t();r&&r(e).bind?r(e).bind(n,o):e.addEventListener&&e.addEventListener(n,o)}function r(e,t){"ON"===n&&console&&console.warn&&console.warn(`[pixel_shop_events_listener] Error in ${e}: ${t.message}`)}function i(e){o(window,"load",(()=>{for(const t of document.forms)e(t)}))}function s(e,t,n){if(t.length!==n.length)throw Error("Payload body and response have different number of items");t.forEach(((t,o)=>{let i=1;try{i=parseInt(n[o].quantity,10)||1}catch(s){r("handleBulkItemCartAddResponse",s)}a(e,t,i)}))}function a(n,o,r){const i=((null===(c=null===(l=t())||void 0===l?void 0:l.ShopifyAnalytics)||void 0===c?void 0:c.meta)||{}).currency,s={id:String(o.id),image:{src:o.image},price:{amount:o.price/100,currencyCode:i},product:{id:String(o.product_id),title:o.title,vendor:o.vendor},sku:o.sku,title:o.variant_title},a={cost:{totalAmount:{amount:s.price.amount*r,currencyCode:i}},merchandise:s,quantity:r};var c,l;n(e,{cartLine:a})}function c(e){if(!e)return 1;try{return JSON.parse(e).quantity||1}catch(t){if(e instanceof FormData){if(e.has("quantity"))return Number(e.get("quantity"))}else{const t=e.split("&");for(const e of t){const t=e.split("=");if("quantity"===t[0])return Number(t[1])}}}return 1}class l{static handleXhrOpen(){}static handleXhrDone(e){try{const t=document.createElement("a");t.href=e.url;const n=t.pathname?t.pathname:e.url;l.ADD_TO_CART_REGEX.test(n)&&l.parsePayloadResponse(e,(t=>{const n=Object.keys(t);if(1===n.length&&"items"===n[0]){const n=t.items;let r;try{r=JSON.parse(e.body).items}catch(o){r=function(e,t){const n=new Array(t);for(let o=0;o{t(JSON.parse(String.fromCharCode(...new Uint8Array(n.result))))})),n.readAsArrayBuffer(e)}static parsePayloadResponse(e,t){e.xhr.response instanceof Blob?l.parseBlobToJson(e.xhr.response,t):e.xhr.responseText&&t(JSON.parse(e.xhr.responseText))}constructor(e,t,n,o,r){this.oldOnReadyStateChange=void 0,this.xhr=void 0,this.url=void 0,this.method=void 0,this.body=void 0,this.publish=void 0,this.xhr=e,this.url=t,this.method=n,this.body=o,this.publish=r}onReadyStateChange(){this.xhr.readyState===XMLHttpRequest.DONE&&l.handleXhrDone({method:this.method,url:this.url,body:this.body,xhr:this.xhr,publish:this.publish}),this.oldOnReadyStateChange&&this.oldOnReadyStateChange.call(this.xhr,new Event("oldOnReadyStateChange"))}}function u(n,u){!function(e,t){const n=e.prototype.open,o=e.prototype.send;e.prototype.open=function(e,t){this._url=t,this._method=e,n.apply(this,arguments)},e.prototype.send=function(e){if(!(e instanceof Document)){const n=new l(this,this._url,this._method,e||"",t);this.addEventListener?this.addEventListener("readystatechange",n.onReadyStateChange.bind(n),!1):(n.oldOnReadyStateChange=this.onreadystatechange,this.onreadystatechange=n.onReadyStateChange)}o.call(this,e)}}(XMLHttpRequest,n),function(e,t){const n=e.fetch;function o(e,n){e.clone().json().then((e=>{const o=n.items,r=e.items;return s(t,r,o),e})).catch(u)}function i(e,n){const o=c(n);e.clone().json().then((e=>a(t,e,o))).catch(u)}function u(e){r("handleFetchRequest",e)}"function"==typeof n&&(e.fetch=function(...e){return n.apply(this,Array.prototype.slice.call(e)).then((e=>{if(!e.ok)return e;const t=document.createElement("a");t.href=e.url;const n=t.pathname?t.pathname:e.url;try{if(l.ADD_TO_CART_REGEX.test(n)){try{const t=JSON.parse(arguments[1].body);if(Object.keys(t).includes("items"))return o(e,t),e}catch(r){u(r)}i(e,arguments[1].body)}}catch(r){u(r)}return e}))})}(t(),n),i((t=>{const i=t.getAttribute("action");i&&i.indexOf("/cart/add")>=0&&o(t,"submit",(t=>{!function(t,n,o){const i=n||window.event;if(i.defaultPrevented)return;const s=i.currentTarget||i.srcElement;if(s&&s instanceof Element&&(s.getAttribute("action")||s.getAttribute("href")))try{const n=function(e){let t;const n=e.querySelector('[name="id"]');return n instanceof HTMLSelectElement&&n.options?t=n.options[n.selectedIndex]:(n instanceof HTMLOptionElement||n instanceof HTMLInputElement)&&(t=n),t}(s);if(!n)return;const r=n.value,i=function(e){const t=e.querySelector('[name="quantity"]');return t instanceof HTMLInputElement?Number(t.value):1}(s),a=function(e,t){var n;let o;const r=null===(n=t.productVariants)||void 0===n?void 0:n.filter((t=>t.id===e));if(!r||!r.length)throw new Error("Product variant not found");return o={...r[0]},o}(r,o),c={cost:{totalAmount:{amount:a.price.amount*i,currencyCode:a.price.currencyCode}},merchandise:a,quantity:i};t(e,{cartLine:c})}catch(a){r("handleSubmitCartAdd",a)}}(n,t,u)}))}))}function d(e,t,s){var a;null!=s&&s.logLevel&&(a=s.logLevel,n=a),u(e,t),function(e,t){i((n=>{const i=n.querySelector('[name="previous_step"]');i&&i instanceof HTMLInputElement&&"payment_method"===i.value&&o(document.body,"submit",(n=>{!function(e,t,n){const o=t||window.event,i=o.target||o.srcElement;if(i&&i instanceof HTMLFormElement&&i.getAttribute("action")&&null!==i.getAttribute("data-payment-form"))try{const t=n.checkout;if(!t)throw new Error("Checkout data not found");e("payment_info_submitted",{checkout:t})}catch(s){r("handleSubmitToPaymentAdd",s)}}(e,n,t)}))}))}(e,t)}l.ADD_TO_CART_REGEX=/^(?:\/[a-zA-Z]+(?:-[a-zA-Z]+)?)?\/cart\/add(?:\.js|\.json)?$/;const p="0.0.171",f={test:"edge_test_click/1.0",load:"web_pixels_manager_load/2.0",init:"web_pixels_manager_init/2.0",register:"web_pixels_manager_pixel_register/2.0",subscriberEventEmit:"web_pixels_manager_subscriber_event_emit/2.0"};function h(e,t){return{schemaId:f[e],payload:t}}function m(e){const t={};for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)){const o=n.replace(/[A-Z]/g,(e=>`_${e}`)).toLowerCase(),r=e[n];t[o]=null!==r&&"object"==typeof r?m(r):r}return t}class b extends Error{constructor(...e){super(...e),Error.captureStackTrace&&Error.captureStackTrace(this,b)}}const y=(e,t)=>{var n;const o={severity:"error",context:"",unhandled:!0,...t};let r="";const i={lineNumber:"1",columnNumber:"1",method:o.context,file:"browser.js"};if(e.stackTrace||e.stack||e.description){r=e.stack.split("\n")[0];const t=e.stack.match(/([0-9]+):([0-9]+)/);if(t&&t.length>2&&(i.lineNumber=t[1],i.columnNumber=t[2],parseInt(i.lineNumber,10)>1e5))return}fetch("https://notify.bugsnag.com",{method:"POST",headers:{"Content-Type":"application/json","Bugsnag-Api-Key":"bcbc9f6762da195561967577c2d74ff8","Bugsnag-Payload-Version":"5"},body:JSON.stringify({payloadVersion:5,notifier:{name:"web-pixel-manager",version:p,url:"-"},events:[{exceptions:[{errorClass:r,message:r,stacktrace:[i],type:"browserjs"}],context:o.context,severity:o.severity,unhandled:o.unhandled,app:{version:p},metaData:{device:{userAgent:null===(n=self.navigator)||void 0===n?void 0:n.userAgent},request:{shopId:o.shopId,shopUrl:self.location.href,pixelId:o.pixelId,pixelType:o.pixelType,runtimeContext:o.runtimeContext},"Additional Notes":{initConfig:JSON.stringify(o.initConfig),notes:o.notes}}}]})}).catch((()=>{}))},g={global:"https://monorail-edge.shopifysvc.com",staging:"https://monorail-edge-staging.shopifycloud.com",test:"https://localhost"};let w;w="global";const v=new Array;function E(e,t=!1){const n={...e,metadata:{eventCreatedAtMs:_()}};v.push(n),t&&A()}function C(e,t,n=!1){E(h(e,t),n)}function A(){const e=[...v];v.length=0,function(e){if(0===e.length)return!1;const t={metadata:{event_sent_at_ms:_()},events:e.map((e=>({schema_id:e.schemaId,payload:m(e.payload),metadata:{event_created_at_ms:e.metadata.eventCreatedAtMs}})))};!function(e){const t=`${g.global}/unstable/produce_batch`;try{if(self.navigator.sendBeacon.bind(self.navigator)(t,e))return!0}catch(o){}const n=new XMLHttpRequest;try{n.open("POST",t,!0),n.setRequestHeader("Content-Type","text/plain"),n.send(e)}catch(r){y(r,{context:"utilities/monorail/sendRequest",unhandled:!1})}}(JSON.stringify(t))}(e)}function _(){return(new Date).getTime()}class x extends Set{constructor(e,t){if(super(),this.maxSize=void 0,this.keep=void 0,Number.isFinite(e)&&!Number.isInteger(e)||e<=0)throw new Error("Invalid maxSize specified");this.maxSize=e,this.keep=t}push(e){if("oldest"===this.keep)this.sizethis.maxSize))for(const t of this)if(this.delete(t),this.size<=this.maxSize)break;return this}}const S={bufferSize:50,replayKeep:"oldest",enableSubscribeAll:!1,subscribeAllKey:"all_events"};class I{constructor(e=S){this.channelSubscribers=new Map,this.replayQueue=void 0,this.options=void 0,this.options=e,this.replayQueue=new x(e.bufferSize,e.replayKeep)}publish(e,t,n={}){var o;if(this.options.enableSubscribeAll&&e===this.options.subscribeAllKey)throw new Error(`Cannot publish to ${String(e)}`);this.replayQueue.push({name:e,payload:t,options:n});const r=(e,n)=>n.apply({},[{...t}]);var i;return null===(o=this.channelSubscribers.get(e))||void 0===o||o.forEach(r),this.options.enableSubscribeAll&&(null===(i=this.channelSubscribers.get(this.options.subscribeAllKey))||void 0===i||i.forEach(r)),!0}subscribe(e,t,n={}){const o=this.channelSubscribers.get(e)||new Map;return this.channelSubscribers.set(e,o.set(t,n)),this.replayQueue.forEach((({name:n,payload:o})=>{(e===n||this.options.enableSubscribeAll&&e===this.options.subscribeAllKey)&&t.apply({},[{...o}])})),()=>o.delete(t)}}const R=["checkout_completed","checkout_started","payment_info_submitted","collection_viewed","page_viewed","product_added_to_cart","product_viewed","product_variant_viewed","search_submitted"],P=["all_events","all_standard_events","all_custom_events","checkout_completed","checkout_started","payment_info_submitted","collection_viewed","page_viewed","product_added_to_cart","product_viewed","product_variant_viewed","search_submitted"];function O(e){return R.includes(e)}function T(e){return P.includes(e)}let D,L,k,N,U,j,M,B;var $,G,V,K,q,z,W,X;(X=D||(D={})).TRACKING_ACCEPTED="trackingConsentAccepted",X.TRACKING_DECLINED="trackingConsentDeclined",X.MARKETING_ACCEPTED="marketingConsentAccepted",X.STATISTICS_ACCEPTED="statisticsConsentAccepted",X.PREFERENCES_ACCEPTED="preferencesConsentAccepted",X.ATTRIBUTION_ACCEPTED="attributionConsentAccepted",X.MARKETING_DECLINED="marketingConsentDeclined",X.STATISTICS_DECLINED="statisticsConsentDeclined",X.PREFERENCES_DECLINED="preferencesConsentDeclined",X.ATTRIBUTION_DECLINED="attributionConsentDeclined",X.CONSENT_COLLECTED="visitorConsentCollected",(W=L||(L={})).V2_0="2.0",W.V2_1="2.1",(z=k||(k={})).ACCEPTED="yes",z.DECLINED="no",z.NO_INTERACTION="no_interaction",z.NO_VALUE="",(q=N||(N={})).NO_VALUE="",q.ACCEPTED="1",q.DECLINED="0",(K=U||(U={})).GDPR="GDPR",K.CCPA="CCPA",K.NO_VALUE="",(V=j||(j={})).CCPA_BLOCK_ALL="CCPA_BLOCK_ALL",V.GDPR="GDPR",V.GDPR_BLOCK_ALL="GDPR_BLOCK_ALL",V.CCPA="CCPA",(G=M||(M={})).MARKETING="m",G.STATISTICS="s",G.PREFERENCES="p",G.ATTRIBUTION="t",($=B||(B={})).MARKETING="marketing",$.STATISTICS="statistics",$.PREFERENCES="preferences",$.ATTRIBUTION="attribution";const F=["lim","v","con","reg"];function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function J(e){for(var t=1;t{const[n,o]=t.split("=");if("_tracking_consent"===decodeURIComponent(n)){var r=JSON.parse(decodeURIComponent(o));e=r}})),void 0!==e&&(t=e,[L.V2_0,L.V2_1].includes(t.v)&&function(e,t){const n=t.slice().sort();return e.length===t.length&&e.slice().sort().every(((e,t)=>e===n[t]))}(Object.keys(t),F)))return e;var t}();if(!e)return;return e.v===L.V2_0?function(e){const t=J(J({},e.con),{},{GDPR:te(e)?ee(e.con.GDPR):void 0});return void 0===t.GDPR&&delete t.GDPR,{con:t,reg:e.reg,v:L.V2_1,lim:e.lim}}(e):e}catch(e){return}}function Z(e=null){return null===e&&(e=Q()),void 0===e}function ee(e){return{[M.MARKETING]:e,[M.STATISTICS]:e,[M.PREFERENCES]:e,[M.ATTRIBUTION]:e}}function te(e){const t=[j.GDPR,j.GDPR_BLOCK_ALL];return e.lim.some((e=>t.includes(e)))&&U.GDPR in e.con}function ne(){if(!re(j.GDPR)&&!re(j.GDPR_BLOCK_ALL))return!0;const e=function(){const e=Q();if(Z(e))return ee(N.NO_VALUE);const t=e.con;switch(typeof t.GDPR){case"undefined":return ee(N.NO_VALUE);case"string":return ee(t.GDPR);default:return t.GDPR}}();return e[M.MARKETING]===N.ACCEPTED&&e[M.STATISTICS]===N.ACCEPTED||e[M.MARKETING]!==N.DECLINED&&e[M.STATISTICS]!==N.DECLINED&&function(){const e=function(){const e=Q();return Z(e)?U.NO_VALUE:e.reg}();return e in U?e:U.NO_VALUE}()!==U.GDPR}function oe(){return!!Z()||ne()}function re(e){return function(){const e=Q();return Z(e)?{limit:[]}:{limit:e.lim}}().limit.includes(e)}function ie(e){document.addEventListener(D.TRACKING_ACCEPTED,e)}j.GDPR,j.GDPR_BLOCK_ALL,j.CCPA_BLOCK_ALL,j.CCPA;const se=["[object String]","[object Number]","[object Boolean]","[object Undefined]","[object Null]"];function ae(e){let t=null;function n(e){return"[object Object]"===Object.prototype.toString.call(e)}return void 0===e||n(e)?{isValid:function e(o){if(Array.isArray(o))return o.every(e);if(n(o))return Object.keys(o).every((t=>e(o[t])));const r=se.includes(Object.prototype.toString.call(o));return r||(t=`${o} must be one of the following types: ${se.join(", ")}`),r}(e),error:t}:(t=`${e} must be an object`,{isValid:!1,error:t})}const ce={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let le;const ue=new Uint8Array(16);function de(){if(!le&&(le="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!le))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return le(ue)}const pe=[];for(let Ue=0;Ue<256;++Ue)pe.push((Ue+256).toString(16).slice(1));const fe=function(e,t,n){if(ce.randomUUID&&!t&&!e)return ce.randomUUID();const o=(e=e||{}).random||(e.rng||de)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=o[e];return t}return function(e,t=0){return(pe[e[t+0]]+pe[e[t+1]]+pe[e[t+2]]+pe[e[t+3]]+"-"+pe[e[t+4]]+pe[e[t+5]]+"-"+pe[e[t+6]]+pe[e[t+7]]+"-"+pe[e[t+8]]+pe[e[t+9]]+"-"+pe[e[t+10]]+pe[e[t+11]]+pe[e[t+12]]+pe[e[t+13]]+pe[e[t+14]]+pe[e[t+15]]).toLowerCase()}(o)};function he(){return{document:{location:{href:window.location.href,hash:window.location.hash,host:window.location.host,hostname:window.location.hostname,origin:window.location.origin,pathname:window.location.pathname,port:window.location.port,protocol:window.location.protocol,search:window.location.search},referrer:document.referrer,characterSet:document.characterSet,title:document.title},navigator:{language:navigator.language,cookieEnabled:navigator.cookieEnabled,languages:navigator.languages,userAgent:navigator.userAgent},window:{innerHeight:window.innerHeight,innerWidth:window.innerWidth,outerHeight:window.outerHeight,outerWidth:window.outerWidth,pageXOffset:window.pageXOffset,pageYOffset:window.pageYOffset,location:{href:window.location.href,hash:window.location.hash,host:window.location.host,hostname:window.location.hostname,origin:window.location.origin,pathname:window.location.pathname,port:window.location.port,protocol:window.location.protocol,search:window.location.search},origin:window.origin,screenX:window.screenX,screenY:window.screenY,scrollX:window.scrollX,scrollY:window.scrollY}}}function me(e){const t={};for(const o of e.split(/ *; */)){const e=o.split("=");try{t[decodeURIComponent(e[0])]=decodeURIComponent(e[1]||"")}catch(n){continue}}return t}const be=Symbol.for("RemoteUi::Retain"),ye=Symbol.for("RemoteUi::Release"),ge=Symbol.for("RemoteUi::RetainedBy");class we{constructor(){this.memoryManaged=new Set}add(e){this.memoryManaged.add(e),e[ge].add(this),e[be]()}release(){for(const e of this.memoryManaged)e[ge].delete(this),e[ye]();this.memoryManaged.clear()}}function ve(e){return Boolean(e&&e[be]&&e[ye])}function Ee(e,{deep:t=!0}={}){const n=ve(e);if(n&&e[be](),t){if(Array.isArray(e))return e.reduce(((e,n)=>Ee(n,{deep:t})||e),n);if("object"==typeof e&&null!=e)return Object.keys(e).reduce(((n,o)=>Ee(e[o],{deep:t})||n),n)}return n}const Ce="_@f";function Ae(e){const t=new Map,n=new Map,o=new Map;return{encode:function o(r){if("object"==typeof r){if(null==r)return[r];if(r instanceof ArrayBuffer)return[r];const e=[];if(Array.isArray(r)){return[r.map((t=>{const[n,r=[]]=o(t);return e.push(...r),n})),e]}return[Object.keys(r).reduce(((t,n)=>{const[i,s=[]]=o(r[n]);return e.push(...s),{...t,[n]:i}}),{}),e]}if("function"==typeof r){if(t.has(r)){const e=t.get(r);return[{[Ce]:e}]}const o=e.uuid();return t.set(r,o),n.set(o,r),[{[Ce]:o}]}return[r]},decode:r,async call(e,t){const o=new we,i=n.get(e);if(null==i)throw new Error("You attempted to call a function that was already released.");try{const e=ve(i)?[o,...i[ge]]:[o];return await i(...r(t,e))}finally{o.release()}},release(e){const o=n.get(e);o&&(n.delete(e),t.delete(o))},terminate(){t.clear(),n.clear(),o.clear()}};function r(t,n){if("object"==typeof t){if(null==t)return t;if(t instanceof ArrayBuffer)return t;if(Array.isArray(t))return t.map((e=>r(e,n)));if(Ce in t){const r=t["_@f"];if(o.has(r))return o.get(r);let i=0,s=!1;const a=()=>{i-=1,0===i&&(s=!0,o.delete(r),e.release(r))},c=()=>{i+=1},l=new Set(n),u=(...t)=>{if(s)throw new Error("You attempted to call a function that was already released.");if(!o.has(r))throw new Error("You attempted to call a function that was already revoked.");return e.call(r,t)};Object.defineProperties(u,{[ye]:{value:a,writable:!1},[be]:{value:c,writable:!1},[ge]:{value:l,writable:!1}});for(const e of l)e.add(u);return o.set(r,u),u}return Object.keys(t).reduce(((e,o)=>({...e,[o]:r(t[o],n)})),{})}return t}}function _e(){return`${xe()}-${xe()}-${xe()}-${xe()}`}function xe(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)}function Se(e){return e.replace(/\/$/,"")}function Ie(e,t,n,o,r,i=!1){let s={};try{s=t.configuration?JSON.parse(t.configuration):{}}catch(h){}return{analytics:{subscribe:(r,s,a)=>(i&&Ee(s),e.subscribe(r,s,{...a,pixelRuntimeConfig:t,shopId:n,surface:o}))},browser:{cookie:{get:async e=>{if(e){let t="";const n=document.cookie.split("; ");for(const o of n){const[n,r]=o.split("=");if(n===e){t=r;break}}return t}return document.cookie},set:async(e,t)=>{if(t){const n=`${e}=${t}`;document.cookie=n}else document.cookie=e;return document.cookie}},sendBeacon:async(e,t="")=>{const n=new window.Blob([t],{type:"text/plain"});return window.navigator.sendBeacon(e,n)},localStorage:{setItem:async(e,t)=>window.localStorage.setItem(e,t),getItem:async e=>window.localStorage.getItem(e),key:async e=>window.localStorage.key(e),removeItem:async e=>window.localStorage.removeItem(e),clear:async()=>window.localStorage.clear(),length:async()=>window.localStorage.length},sessionStorage:{setItem:async(e,t)=>window.sessionStorage.setItem(e,t),getItem:async e=>window.sessionStorage.getItem(e),key:async e=>window.sessionStorage.key(e),removeItem:async e=>window.sessionStorage.removeItem(e),clear:async()=>window.sessionStorage.clear(),length:async()=>window.sessionStorage.length}},settings:s,init:(a=r,{context:he(),data:{customer:(f=null==a?void 0:a.customer,f?{id:null==f?void 0:f.id,email:null==f?void 0:f.email,phone:null==f?void 0:f.phone}:null),cart:(c=null==a?void 0:a.cart,c?{id:null==c?void 0:c.id,cost:{totalAmount:{amount:null==c||null===(l=c.cost)||void 0===l||null===(u=l.totalAmount)||void 0===u?void 0:u.amount,currencyCode:null==c||null===(d=c.cost)||void 0===d||null===(p=d.totalAmount)||void 0===p?void 0:p.currencyCode}},lines:null==c?void 0:c.lines,totalQuantity:null==c?void 0:c.totalQuantity}:null)}}),_pixelInfo:{...t}};var a,c,l,u,d,p,f}let Re,Pe;function Oe({webPixelConfig:e,eventBus:t,shopId:n,storefrontBaseUrl:o,webPixelsExtensionBaseUrl:r,cdnBaseUrl:i,surface:s,initData:a}){const c=[r,"/app","/services",`/${n}`,"/web-pixels-manager",`/${e.type.toLowerCase()}`,`/web-pixel-${e.id}`,`@${e.scriptVersion}.js`].join("");let l;if(e.type===Pe.App&&e.runtimeContext===Re.Strict){const e=[Se(i),"/shopifycloud/web-pixels-manager/0.0.171/sandbox.modern.js"].join(""),t=new Blob([`importScripts('${e}');`],{type:"text/javascript"});l=new Worker(URL.createObjectURL(t))}else{let{search:t}=window.location;o.match(/spin\.dev\/?/)&&(t=`${t}${t.length?"&":"?"}fast_storefront_renderer=1`);const n=[Se(o),"/web-pixels-manager@0.0.171","/sandbox",window.location.pathname,t].join("");l=function(e,{terminate:t=!0,targetOrigin:n="*"}={}){if("undefined"==typeof window)throw new Error("You can only run fromIframe() in a browser context, but no window was found.");const o=new WeakMap,r=new Promise((t=>{window.addEventListener("message",(n=>{n.source===e.contentWindow&&"remote-ui::ready"===n.data&&t()}))}));return{async postMessage(t,o){await r,e.contentWindow.postMessage(t,n,o)},addEventListener(t,n){const r=t=>{t.source===e.contentWindow&&n(t)};o.set(n,r),self.addEventListener(t,r)},removeEventListener(e,t){const n=o.get(t);null!=n&&(o.delete(t),self.removeEventListener(e,n))},terminate(){t&&e.remove()}}}(function({id:e,src:t,srcdoc:n,privileges:o}){const r=document.querySelector(`iframe#sandbox-${e}`);if(r&&"IFRAME"===r.tagName)return r;const i=document.createElement("iframe");if(t)i.setAttribute("src",t);else{if(!n){const e=new b("src or srcdoc must be provided");throw y(e,{context:"createIframe",unhandled:!1,severity:"warning"}),e}i.setAttribute("srcdoc",n)}return i.setAttribute("id",`sandbox-${e}`),i.setAttribute("sandbox",o.join(" ")),i.setAttribute("tabIndex","-1"),i.setAttribute("aria-hidden","true"),i.setAttribute("style","display:none; height:0; width:0; visibility: hidden;"),function(e){let t=document.querySelector("#WebPixelsManagerSandboxContainer");null==t&&(t=document.createElement("div"),t.setAttribute("id","WebPixelsManagerSandboxContainer"),document.body.appendChild(t)),t.appendChild(e)}(i),i}({id:`web-pixel-extension-${e.type}-${e.id}`,src:n,privileges:["allow-scripts","allow-forms"]}))}const u=function(e,{uuid:t=_e,createEncoder:n=Ae,callable:o}={}){let r=!1,i=e;const s=new Map,a=new Map,c=function(e,t){let n;if(null==t){if("function"!=typeof Proxy)throw new Error("You must pass an array of callable methods in environments without Proxies.");const t=new Map;n=new Proxy({},{get(n,o){if(t.has(o))return t.get(o);const r=e(o);return t.set(o,r),r}})}else{n={};for(const o of t)Object.defineProperty(n,o,{value:e(o),writable:!1,configurable:!0,enumerable:!0})}return n}(p,o),l=n({uuid:t,release(e){u(3,[e])},call(e,n,o){const r=t(),i=f(r,o),[s,a]=l.encode(n);return u(5,[r,e,s],a),i}});return i.addEventListener("message",d),{call:c,replace(e){const t=i;i=e,t.removeEventListener("message",d),e.addEventListener("message",d)},expose(e){for(const t of Object.keys(e)){const n=e[t];"function"==typeof n?s.set(t,n):s.delete(t)}},callable(...e){if(null!=o)for(const t of e)Object.defineProperty(c,t,{value:p(t),writable:!1,configurable:!0,enumerable:!0})},terminate(){u(2,void 0),h(),i.terminate&&i.terminate()}};function u(e,t,n){r||i.postMessage(t?[e,t]:[e],n)}async function d(e){const{data:t}=e;if(null!=t&&Array.isArray(t))switch(t[0]){case 2:h();break;case 0:{const e=new we,[o,r,i]=t[1],a=s.get(r);try{if(null==a)throw new Error(`No '${r}' method is exposed on this endpoint`);const[t,n]=l.encode(await a(...l.decode(i,[e])));u(1,[o,void 0,t],n)}catch(n){const{name:e,message:t,stack:r}=n;throw u(1,[o,{name:e,message:t,stack:r}]),n}finally{e.release()}break}case 1:{const[e]=t[1];a.get(e)(...t[1]),a.delete(e);break}case 3:{const[e]=t[1];l.release(e);break}case 6:{const[e]=t[1];a.get(e)(...t[1]),a.delete(e);break}case 5:{const[e,o,r]=t[1];try{const t=await l.call(o,r),[n,i]=l.encode(t);u(6,[e,void 0,n],i)}catch(n){const{name:t,message:o,stack:r}=n;throw u(6,[e,{name:t,message:o,stack:r}]),n}break}}}function p(e){return(...n)=>{if(r)return Promise.reject(new Error("You attempted to call a function on a terminated web worker."));if("string"!=typeof e&&"number"!=typeof e)return Promise.reject(new Error(`Can’t call a symbol method on a remote endpoint: ${e.toString()}`));const o=t(),i=f(o),[s,a]=l.encode(n);return u(0,[o,e,s],a),i}}function f(e,t){return new Promise(((n,o)=>{a.set(e,((e,r,i)=>{if(null==r)n(i&&l.decode(i,t));else{const e=new Error;Object.assign(e,r),o(e)}}))}))}function h(){var e;r=!0,s.clear(),a.clear(),null===(e=l.terminate)||void 0===e||e.call(l),i.removeEventListener("message",d)}}(l,{callable:["initialize","initWebPixelsAwaitingConsent"]}),d=Ie(t,e,n,s,a,!0),f={cookieRestrictedDomains:async()=>function(){const e=[];return self.location.hostname.split(".").reverse().reduce(((t,n)=>{const o=""===t?n:`${n}.${t}`;return r=o,document.cookie=`wpm-domain-test=1; path=/; domain=${r}`,document.cookie.split(";").find((e=>e.includes("wpm-domain-test")))||e.push(o),function(e){document.cookie=`wpm-domain-test=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=${e}`}(o),o;var r}),""),e}(),userCanBeTracked:async()=>oe(),self:{origin:{get:async()=>self.origin}},document:{referrer:{get:async()=>document.referrer}},monorail:{register:async({status:t,errorMsg:o})=>{const r=Te(e);C("register",{version:p,pageUrl:self.location.href,shopId:n,surface:s,pixelId:e.id,pixelAppId:r,pixelSource:e.type,pixelRuntimeContext:e.runtimeContext,pixelScriptVersion:e.scriptVersion,pixelConfiguration:null==e?void 0:e.configuration,pixelEventSchemaVersion:e.eventPayloadVersion,status:t,errorMsg:o},!0)}}};u.expose({pixelRuntimeAPI:()=>d,sandboxInternalAPI:()=>f});const h=self.document.title;return u.call.initialize(h,c,e),ie((()=>{u.call.initWebPixelsAwaitingConsent()})),{config:e,endpoint:u}}function Te(e){return e.type===Pe.Custom?"-1":e.apiClientId?`${e.apiClientId}`:void 0}!function(e){e.Strict="STRICT",e.Lax="LAX",e.Sandboxed="SANDBOXED",e.Unsandboxed="UNSANDBOXED"}(Re||(Re={})),function(e){e.App="APP",e.Custom="CUSTOM"}(Pe||(Pe={}));const De="all_standard_events",Le="all_custom_events";function ke(e){try{return new URL(e),!0}catch(t){return function(e){const t=new RegExp("^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)*[a-z]{1,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i");return Boolean(t.test(e))}(e)}}const Ne=function(){const e=h("load",{version:p,pageUrl:self.location.href,status:"loading"});try{const t=new Map;return e.payload.status="loaded",E(e),{init(e){const{shopId:n,storefrontBaseUrl:o,cdnBaseUrl:r,webPixelsConfigList:i,surface:s="unknown",initData:a}=e||{},c=function(e){const t=new I({bufferSize:Number.POSITIVE_INFINITY,replayKeep:"oldest",enableSubscribeAll:!0,subscribeAllKey:De}),n=new I({bufferSize:1e3,replayKeep:"oldest",enableSubscribeAll:!0,subscribeAllKey:Le}),o=function(){const e=new Set;return ie((function(){e.forEach((t=>{e.delete(t),t()}))})),{gate(t,n={runOnAccept:!0}){oe()?t():n.runOnAccept&&e.add(t)}}}();return{publish(e,n){if("string"!=typeof e)throw new Error("Expected event name to be a string, but got "+typeof e);if(!O(e))return!1;const o=ae(n);if(!o.isValid)return console.error(o.error),!1;const r=function(e,t,n){return{id:fe(),clientId:me(document.cookie)._shopify_y,timestamp:(new Date).toISOString(),name:e,context:he(),data:{...n||{}}}}(e,0,n);return t.publish(e,r)},publishCustomEvent(e,t){if("string"!=typeof e)throw new Error("Expected event name to be a string, but got "+typeof e);if(O(e)||T(e))return!1;const o=ae(t);if(!o.isValid)return console.error(o.error),!1;const r=function(e,t,n=null){return{id:fe(),clientId:me(document.cookie)._shopify_y,timestamp:(new Date).toISOString(),name:e,context:he(),customData:n}}(e,0,t);return n.publish(e,r)},subscribe(e,r,i={}){const s=e=>{o.gate((()=>{var t;const n=i.schemaVersion||i.pixelRuntimeConfig.eventPayloadVersion;r(e),C("subscriberEventEmit",{version:p,pageUrl:self.location.href,shopId:i.shopId,surface:i.surface,pixelId:i.pixelRuntimeConfig.id,pixelAppId:Te(i.pixelRuntimeConfig),pixelSource:i.pixelRuntimeConfig.type,pixelRuntimeContext:i.pixelRuntimeConfig.runtimeContext,pixelScriptVersion:i.pixelRuntimeConfig.scriptVersion,pixelConfiguration:null===(t=i.pixelRuntimeConfig)||void 0===t?void 0:t.configuration,pixelEventSchemaVersion:n,eventName:e.name,eventType:O(e.name)?"standard":"custom"},!0)}))};if("all_events"===e){const e=t.subscribe(De,s,i),o=n.subscribe(Le,s,i);return()=>e()&&o()}return e===Le?n.subscribe(Le,s,i):e===De||T(e)?t.subscribe(e,s,i):n.subscribe(e,s,i)}}}(),l=e.webPixelsExtensionBaseUrl||e.webPixelExtensionBaseUrl,u={severity:"warning",context:"createWebPixelsManager/init",unhandled:!1,shopId:n,initConfig:e},f=h("init",{version:p,pageUrl:self.location.href,shopId:n,surface:s,status:"initializing"});try{if(!n){const e=new b("WebPixelsManager: shopId is required");throw y(e,u),e}if(!o){const e=new b("WebPixelsManager: storefrontBaseUrl is required");throw y(e,u),e}if(!ke(o)){const e=new b(`WebPixelsManager: storefrontBaseUrl is not a valid absolute URL: ${o}`);throw y(e,u),e}if(!l){const e=new b("WebPixelsManager: webPixelsExtensionBaseUrl is required");throw y(e,u),e}if(!ke(l)){const e=new b(`WebPixelsManager: webPixelsExtensionBaseUrl is not a valid absolute URL: ${l}`);throw y(e,u),e}if(!r){const e=new b("WebPixelsManager: cdnBaseUrl is required");throw y(e,u),e}if(!ke(r)){const e=new b(`WebPixelsManager: cdnBaseUrl is not a valid absolute URL: ${r}`);throw y(e,u),e}return i.forEach((e=>{const i=(u=e.id,`${e.type.toLowerCase()}/${u}`);var u;if(!t.has(i)&&function(e){const t={eventPayloadVersion:"string",id:"number",runtimeContext:"string",scriptVersion:"string",type:"string"};return e.type===Pe.App&&(t.configuration="string"),Object.keys(e).filter((n=>Object.prototype.hasOwnProperty.call(t,n)&&typeof e[n]===t[n])).length===Object.keys(t).length}(e)){const u=Oe({webPixelConfig:e,eventBus:c,shopId:n,storefrontBaseUrl:o,webPixelsExtensionBaseUrl:l,cdnBaseUrl:r,surface:s,initData:a});t.set(i,u)}else console.warn("Web Pixel config is invalid or already configured")})),"checkout-one"!==s&&d(c.publish,a),f.payload.status="initialized",E(f),{publish:(e,t,n={})=>c.publish(e,t),publishCustomEvent:(e,t,n={})=>c.publishCustomEvent(e,t)}}catch(m){return m instanceof b||y(m,{context:"init",shopId:n,initConfig:e}),self.console&&console.error(m),f.payload.status="failed",f.payload.errorMsg=null==m?void 0:m.message,E(f),{publish:(...e)=>!1,publishCustomEvent:(...e)=>!1}}finally{A()}}}}catch(t){return t instanceof b||y(t,{context:"createWebPixelsManager"}),self.console&&console.error(t),e.payload.status="failed",e.payload.errorMsg=null==t?void 0:t.message,E(e,!0),{}}}();self.webPixelsManager=Ne})();